<%@ page language="java" pageEncoding="UTF-8" %>
<%@ include file="../portal_common/taglibs.jsp" %>
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/>
    <title>我的订单</title>
    <link rel="icon" href="assets/img/favicon.ico">

    <link rel="stylesheet" type="text/css" href="${ctx}/css/webbase.css"/>
    <link rel="stylesheet" type="text/css" href="${ctx}/css/pages-seckillOrder.css"/>
</head>

<body>
<!-- 头部栏位 -->
<!--页面顶部-->
<div id="nav-bottom">
    <!--顶部-->
    <%@include file="../portal_common/top.jsp" %>
</div>

<script type="text/javascript" src="${ctx}/js/plugins/jquery/jquery.min.js"></script>
<script type="text/javascript">
    $(function () {
        $("#service").hover(function () {
            $(".service").show();
        }, function () {
            $(".service").hide();
        });
        $("#shopcar").hover(function () {
            $("#shopcarlist").show();
        }, function () {
            $("#shopcarlist").hide();
        });

    })
</script>
<script type="text/javascript" src="${ctx}/js/plugins/jquery.easing/jquery.easing.min.js"></script>
<script type="text/javascript" src="${ctx}/js/plugins/sui/sui.min.js"></script>
<script type="text/javascript" src="${ctx}/js/plugins/jquery-placeholder/jquery.placeholder.min.js"></script>
<script type="text/javascript" src="${ctx}/js/widget/nav.js"></script>
</body>
<!--header-->
<div id="account">
    <div class="py-container">
        <div class="yui3-g home">
            <!--左侧列表-->
            <div class="yui3-u-1-6 list">

                <div class="person-info">
                    <div class="person-photo">
                        <c:if test="${headPic == null}">
                            <img src="${ctx}/img/_/photo.png" alt="">
                        </c:if>
                        <c:if test="${headPic != null}">
                            <img width="60px" height="60px" src="${headPic}" alt="">
                        </c:if>
                    </div>
                    <div class="person-account">
                        <span class="name">${username}</span>
                    </div>
                    <div class="clearfix"></div>
                </div>
                <div class="list-items">
                    <dl>
                        <dt><i>·</i> 订单中心</dt>
                        <dd><a href="${ctx}/order/list"
                               <c:if test="${status == null}">class="list-active"</c:if>>我的订单</a></dd>
                        <dd><a href="${ctx}/order/list?status=1"
                               <c:if test="${status  == '1'}">class="list-active"</c:if>>待付款</a>
                        </dd>
                        <dd><a href="${ctx}/order/list?status=3" <c:if test="${status == 3}">class="list-active"</c:if>>待发货</a>
                        </dd>
                        <dd><a href="${ctx}/order/list?status=4" <c:if test="${status == 4}">class="list-active"</c:if>>待收货</a>
                        </dd>
                        <dd><a href="${ctx}/order/list?status=6" <c:if test="${status == 6}">class="list-active"</c:if>>待评价</a>
                        </dd>
                        <dd><a href="${ctx}/order/list?status=2" <c:if test="${status == 2}">class="list-active"</c:if>>交易关闭</a>
                        </dd>
                    </dl>
                    <dl>
                        <dt><i>·</i> 设置</dt>
                        <dd><a href="${ctx}/user/details">个人信息</a></dd>
                        <dd><a href="${ctx}/address/list">地址管理</a></dd>
                    </dl>
                </div>
            </div>
            <!--右侧主内容-->
            <div class="yui3-u-5-6 order-pay">
                <div class="body">
                    <div class="table-title">
                        <table class="sui-table  order-table">
                            <tr>
                                <thead>
                                <th width="35%">宝贝</th>
                                <th width="5%">单价</th>
                                <th width="5%">数量</th>
                                <th width="8%">实付款</th>
                                <th width="10%">总计</th>
                                <th width="10%">交易状态</th>
                                <th width="10%">交易操作</th>
                                </thead>
                            </tr>
                        </table>
                    </div>
                    <div class="order-detail">
                        <div class="orders">
                            <!--order1-->
                            <c:forEach items="${list}" var="row">
                                <div class="choose-title">
                                    <label data-toggle="checkbox" class="checkbox-pretty ">
                                        <input type="checkbox" checked="checked"><span>
                                        <fmt:formatDate value="${row.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/>
                                        　订单编号：${row.orderId}  店铺：${row.nickName} </span>
                                    </label>
                                </div>
                                <table class="sui-table table-bordered order-datatable">
                                    <tbody>
                                    <c:forEach items="${row.itemList}" var="item" varStatus="status">
                                        <tr>
                                            <td width="35%">
                                                <div class="typographic"><img width="82px" height="82px"
                                                                              src="${item.picPath}"/>
                                                    <a href="#" class="block-text">${item.title}</a>
                                                        <%--<span class="guige">规格：温泉喷雾150ml</span>--%>
                                                </div>
                                            </td>
                                            <td width="5%" class="center">
                                                <ul class="unstyled">
                                                    <li>¥${item.price}.00</li>
                                                </ul>
                                            </td>
                                            <td width="5%" class="center">${item.num}</td>
                                            <td width="8%" class="center">
                                                <ul class="unstyled">
                                                    <li>${item.totalFee}.00</li>
                                                </ul>
                                            </td>
                                            <c:if test="${status.index == 0}">
                                                <td width="10%" class="center" rowspan="${row.itemList.size()}">
                                                    <ul class="unstyled">
                                                        <li>${row.payment}.00</li>
                                                        <li>（含运费：￥0.00）</li>
                                                    </ul>
                                                </td>
                                            </c:if>
                                                <%-- ['0', '1未付款', '2交易关闭', '3已付款', '4已发货', '5交易成功', '6待评价', '7已评价'];--%>
                                            <c:if test="${status.index == 0}">
                                                <c:choose>
                                                    <c:when test="${row.status == 1}">
                                                        <td width="10%" class="center" rowspan="${row.itemList.size()}">
                                                            <ul class="unstyled">
                                                                <li>等待卖家付款</li>
                                                                <li><a href="" class="btn">订单详情 </a></li>
                                                            </ul>
                                                        </td>
                                                        <td width="10%" class="center" rowspan="${row.itemList.size()}">
                                                            <ul class="unstyled">
                                                                <li><a href="#" class="sui-btn btn-info"
                                                                       onclick="payment('${row.orderId}')">立即付款</a></li>
                                                                <li><a href="#"
                                                                       onclick="cancelOrder('${row.orderId}')">取消订单</a>
                                                                </li>
                                                            </ul>
                                                        </td>
                                                    </c:when>
                                                    <c:when test="${row.status == 2}">
                                                        <td width="10%" class="center" rowspan="${row.itemList.size()}">
                                                            <ul class="unstyled">
                                                                <li>交易关闭</li>
                                                                <li><a href="" class="btn">订单详情 </a></li>
                                                            </ul>
                                                        </td>
                                                        <td width="10%" class="center" rowspan="${row.itemList.size()}">
                                                            <ul class="unstyled">
                                                                <li><a href="${ctx}/itemSearch?keywords=${item.title}"
                                                                       class="sui-btn btn-info">重新购买</a></li>
                                                            </ul>
                                                        </td>
                                                    </c:when>
                                                    <%-- ['0', '1未付款', '2交易关闭', '3已付款', '4已发货', '5交易成功', '6待评价', '7已评价'];--%>
                                                    <c:when test="${row.status == 3}">
                                                        <td width="10%" class="center" rowspan="${row.itemList.size()}">
                                                            <ul class="unstyled">
                                                                <li>已付款，待买家发货</li>
                                                                <li><a href="" class="btn">订单详情 </a></li>
                                                            </ul>
                                                        </td>
                                                        <td width="10%" class="center" rowspan="${row.itemList.size()}">
                                                            <ul class="unstyled">
                                                                <li>还剩4天23时</li>
                                                                <li><a href="#" class="sui-btn btn-info">提醒发货</a></li>
                                                            </ul>
                                                        </td>
                                                    </c:when>
                                                    <c:when test="${row.status == 4}">
                                                        <td width="10%" class="center " rowspan="${row.itemList.size()}">
                                                            <ul class="unstyled">
                                                                <li>买家已发货，待买家收货</li>
                                                                <li><a href="" class="btn">订单详情 </a></li>
                                                            </ul>
                                                        </td>
                                                        <td width="10%" class="center" rowspan="${row.itemList.size()}">
                                                            <ul class="unstyled">
                                                                <li>还剩2天10时</li>
                                                                <li><a href="#" class="sui-btn btn-info"
                                                                       onclick="receipt('${row.orderId}')">确认收货</a></li>
                                                            </ul>
                                                        </td>
                                                    </c:when>
                                                    <c:when test="${row.status == 6}">
                                                        <td width="10%" class="center" rowspan="${row.itemList.size()}">
                                                            <ul class="unstyled">
                                                                <li>已确认收货，待评价</li>
                                                                <li><a href="" class="btn">订单详情 </a></li>
                                                            </ul>
                                                        </td>
                                                        <td width="10%" class="center" rowspan="${row.itemList.size()}">
                                                            <ul class="unstyled">
                                                                <li><a href="#" class="sui-btn btn-info"
                                                                       onclick="commentary('${row.orderId}')">评价</a>
                                                                </li>
                                                                <li>申请售后</li>
                                                            </ul>
                                                        </td>
                                                    </c:when>
                                                    <c:when test="${row.status == 7}">
                                                        <td width="10%" class="center" rowspan="${row.itemList.size()}">
                                                            <ul class="unstyled">
                                                                <li>已评价:${row.buyerMessage}</li>
                                                                <li><a href="" class="btn">订单详情 </a></li>
                                                            </ul>
                                                        </td>
                                                        <td width="10%" class="center" rowspan="${row.itemList.size()}">
                                                            <ul class="unstyled">
                                                                <li>申请售后</li>
                                                            </ul>
                                                        </td>
                                                    </c:when>
                                                    <c:otherwise></c:otherwise>
                                                </c:choose></c:if>
                                        </tr>
                                    </c:forEach>
                                    </tbody>
                                </table>
                            </c:forEach>
                            <%--<div class="choose-order">
                                <div class="sui-pagination pagination-large top-pages">
                                    <ul>
                                        <li class="prev disabled"><a href="#">«上一页</a></li>
                                        <li class="active"><a href="#">1</a></li>
                                        <li><a href="#">2</a></li>
                                        <li><a href="#">3</a></li>
                                        <li class="dotted"><span>...</span></li>
                                        <li class="next"><a href="#">下一页»</a></li>
                                    </ul>
                                    <div><span>共10页&nbsp;</span>
                                    </div>
                                </div>
                                <div class="clearfix"></div>
                            </div>--%>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- 底部栏位 -->
        <!--页面底部-->
        <%@include file="../portal_common/foot.jsp" %>
        <!--页面底部END-->
        <script>
            // 付款
            function payment(orderId) {
                $.ajax({
                        url: "${ctx}/order/edit/status",
                        type: 'post',
                        data: {
                            'orderId': orderId,
                            'status': '3'
                        },
                        dataType: 'json',
                        success: function (response) {
                            console.log(response);
                            if (response.success) {
                                alert(response.message);
                                window.location.reload();
                            } else {
                                alert(response.message);
                            }
                        }
                    }
                );
            }

            // 取消订单
            function cancelOrder(orderId) {
                $.ajax({
                        url: "${ctx}/order/edit/status",
                        type: 'post',
                        data: {
                            'orderId': orderId,
                            'status': '2'
                        },
                        dataType: 'json',
                        success: function (response) {
                            console.log(response);
                            if (response.success) {
                                alert(response.message);
                                window.location.reload();
                            } else {
                                alert(response.message);
                            }
                        }
                    }
                );
            }

            // 确认收货
            function receipt(orderId) {
                $.ajax({
                        url: "${ctx}/order/edit/status",
                        type: 'post',
                        data: {
                            'orderId': orderId,
                            'status': '6'
                        },
                        dataType: 'json',
                        success: function (response) {
                            console.log(response);
                            if (response.success) {
                                alert(response.message);
                                window.location.reload();
                            } else {
                                alert(response.message);
                            }
                        }
                    }
                );
            }

            // 默认好评
            function commentary(orderId) {
                $.ajax({
                        url: "${ctx}/order/edit/status",
                        type: 'post',
                        data: {
                            'orderId': orderId,
                            'buyerMessage': '默认好评',
                            'status': '7'
                        },
                        dataType: 'json',
                        success: function (response) {
                            console.log(response);
                            if (response.success) {
                                alert(response.message);
                                window.location.reload();
                            } else {
                                alert(response.message);
                            }
                        }
                    }
                );
            }
        </script>
</html>